Update User Profile
User Management
Update User Profile
Update the authenticated user profile information including avatar upload
PUT
Update User Profile
Overview
This endpoint allows authenticated users to update their profile information. Users can only update their own profile. Supports partial updates and avatar image uploads.Authentication
This endpoint requires authentication. Include a valid JWT access token in the Authorization header:Authorization
Users can only update their own profile. The authenticated user must match the user ID in the URL path, otherwise a 403 Forbidden error is returned.Request
Endpoint
Path Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| id | integer | The user ID (must match authenticated user) | Yes |
Headers
| Header | Value | Required |
|---|---|---|
| Authorization | Bearer | Yes |
| Content-Type | application/json or multipart/form-data | Yes |
Request Body
Supports partial updates. All fields are optional:Avatar Upload
To upload an avatar, usemultipart/form-data encoding and include the avatar file field:
Request Fields
| Field | Type | Description | Constraints |
|---|---|---|---|
| username | string | User’s username | Optional, unique |
| string | User’s email address | Optional, unique, max 200 chars | |
| first_name | string | User’s first name | Optional, max 200 chars |
| last_name | string | User’s last name | Optional, max 200 chars |
| number_phone | string | User’s phone number | Optional, max 10 chars |
| avatar | file | Profile image file | Optional, image file (jpg, png, etc.) |
Response
Success Response (200 OK)
Returns the updated user profile data:Response Fields
| Field | Type | Description |
|---|---|---|
| id | integer | Unique user identifier |
| username | string | User’s username |
| string | User’s email address | |
| first_name | string | User’s first name |
| last_name | string | User’s last name |
| number_phone | string | User’s phone number |
| avatar | string | URL path to user’s avatar image |
| date_joined | datetime | When the user account was created |
| last_login | datetime | Last login timestamp |
| is_active | boolean | Whether the user account is active |
| is_staff | boolean | Whether user has staff privileges |
| is_superuser | boolean | Whether user has superuser privileges |
Error Responses
400 Bad Request
Returned when the request data is invalid:401 Unauthorized
Returned when the authentication token is missing or invalid:403 Forbidden
Returned when the authenticated user tries to update another user’s profile:404 Not Found
Returned when the user ID doesn’t exist:500 Internal Server Error
Returned when an unexpected error occurs:Example Requests
Update Basic Information (JSON)
Update with Avatar Upload (Multipart)
Partial Update (Single Field)
Example Response
Implementation Details
This endpoint is implemented in/apps/users/views.py:97 as the update_profile function view:
- Decorated with
@permission_classes([IsAuthenticated])to require authentication - Verifies that
request.usermatches the user being updated (authorization check) - Supports
MultiPartParserandFormParserfor file uploads - Handles avatar file uploads separately before serializer validation
- Uses
UsersSerializerwithpartial=Trueto allow partial updates - Returns updated user data on success
Notes
- Partial updates are supported - you only need to include fields you want to change
- Avatar images are uploaded to the
media/avatars/directory - Email and username must remain unique across all users
- The endpoint uses PUT method but supports partial updates (PATCH-like behavior)
Related Endpoints
- Get Profile - Retrieve user profile information
- Delete User - Delete user account
